package cn.jlonely.xyhx.admin.controller;

import cn.jlonely.xyhx.admin.service.NotificationService;
import cn.jlonely.xyhx.pojo.Notification;
import cn.jlonely.xyhx.utils.PageResult;
import cn.jlonely.xyhx.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin")
public class NotificationController {

    @Autowired
    private NotificationService notificationService;

    /**
     * 获取通知分页
     * @return
     */
    @GetMapping("/getNotificationPage")
    public Result getNotificationPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
         PageResult<Notification> notificationList = notificationService.getNotificationPage(page, pageSize);
        return Result.success(notificationList);
    }

    /**
     * 删除通知
     * @param id
     * @return
     */
    @DeleteMapping("/deleteNotification")
    public Result deleteNotification(@RequestParam("id") Integer id) {
        notificationService.deleteNotification(id);
        return Result.success();
    }

    @PostMapping("/createNotification")
    public Result createNotification(@RequestBody Notification notification) {
        notificationService.createNotification(notification);
        return Result.success();
    }
}
